import { EquipControllerBase } from "./EquipControllerBase";
import { EItemUpdateOper } from "../../../Message/Game/EItemUpdateOper";
import { IEquipmentModule } from "../../../modules/interfaces/IEquipmentModule";
import { IView } from "../../mvc/interfaces/IView";
import { EquipmentModule } from "../../../modules/EquipmentModule";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { DataEvent } from "../events/DataEvent";
import { BatchRefreshData } from "../view/equipment/data/BatchRefreshData";
import { GameProxy } from "../mvc/GameProxy";
import { EEquipRefreshOperType } from "../../../Message/Game/EEquipRefreshOperType";
import { EquipUpdateParams } from "../view/equipment/data/EquipUpdateParams";
import { EEquipRefreshNumType } from "../../../Message/Game/EEquipRefreshNumType";
import { ItemData } from "../resource/info/ItemData";
import { EItemUpdateType } from "../../../Message/Game/EItemUpdateType";
import { MsgManager } from "../manager/MsgManager";
import { Language } from "../../../extend/language/Language";
import { EProp } from "../../../Message/Public/EProp";
import { EBind } from "../../../Message/Public/EBind";
import { ItemConfig } from "../resource/ItemConfig";
import { ItemInfo } from "../resource/info/ItemInfo";
import { ECategory } from "../../../Message/Public/ECategory";
import { EquipAdvanceConfig } from "../resource/EquipAdvanceConfig";
import { Cache } from "../cache/Cache";
import { TempRefreshData } from "../view/equipment/data/TempRefreshData";
import { ItemsUtil } from "../view/shortcuts/item/ItemsUtil";
import { TItemWeapon } from "../../../Message/Db/Tables/TItemWeapon";
import { _EBindYes } from "../../../EBind/_EBindYes";
type int = number;
//class EquipmentController
    
    export  class EquipmentController extends EquipControllerBase
    {
        constructor()
        {
            
            super();_opertionType = EItemUpdateOper._EItemUpdateOperStrengthen;
            return;
        }

        public set currentUpdateType(arg1: int)
        {
            this._currentUpdateType = arg1;
            return;
        }

        public get currentUpdateType(): int
        {
            return this._currentUpdateType;
        }

        public get equipModule(): IEquipmentModule
        {
            if (!this._equipModule) 
            {
                this.initView();
            }
            return this._equipModule;
        }

        protected /* override */ initView(): IView
        {
            if (!this._equipModule) 
            {
                this._equipModule = new EquipmentModule();
                addCommonListeners(this._equipModule);
            }
            return this._equipModule;
        }

        protected /* override */ initServer(): void
        {
            super.initServer();
            Dispatcher.addEventListener(EventName.Equipment_DoCast_Strengthen, this.doCastHandler);
            Dispatcher.addEventListener(EventName.Equipment_DoCast_Recast, this.doCastHandler);
            Dispatcher.addEventListener(EventName.Equipment_DoCast_EquipDecompose, this.doCastHandler);
            Dispatcher.addEventListener(EventName.Equipment_DoCast_EquipMerge, this.doCastHandler);
            Dispatcher.addEventListener(EventName.Equipment_DoCast_EquipAdvance, this.doCastHandler);
            Dispatcher.addEventListener(EventName.Equipment_DoCast_EquipAdvanceColor, this.doCastHandler);
            Dispatcher.addEventListener(EventName.Equipment_DoCast_EquipPrefixUpgrade, this.doCastHandler);
            Dispatcher.addEventListener(EventName.Equipment_ReplaceBatchRefresh, this.doReplaceBatchRefreshAtt);
            Dispatcher.addEventListener(EventName.Equipment_DoBatchRefresh, this.doBatchRefresh);
            Dispatcher.addEventListener(EventName.Guide_EquipBuild, this.onGuideEquipBuildHandler);
            return;
        }

        protected /* override */ onShowHandler(arg1: Object /* flash.events.Event */): void
        {
            super.onShowHandler(arg1);
            this._equipModule.checkGuide();
            Dispatcher.dispatchEvent(new DataEvent(EventName.Equipment_WindowOpen));
            return;
        }

        protected /* override */ useBindChangeHandler(arg1: DataEvent): void
        {
            cache.equipment.isUseBind_equip = Boolean(arg1.data);
            super.useBindChangeHandler(arg1);
            return;
        }

        /* internal  */doReplaceBatchRefreshAtt(arg1: DataEvent): void
        {
            var loc1=arg1.data as BatchRefreshData;
            GameProxy.equipmentProxy.equipRefresh(loc1.equipData.posType, loc1.equipData.uid, "", EEquipRefreshOperType._EEquipRefreshReplace, false, null, null, 0, null, loc1.index, 0, false, false);
            return;
        }

        /* internal  */doBatchRefresh(arg1: DataEvent): void
        {
            var loc1=arg1.data as EquipUpdateParams;
            GameProxy.equipmentProxy.equipRefresh(loc1.equipPosType, loc1.equipUid, "", EEquipRefreshOperType._EEquipRefreshNormal, loc1.flag, loc1.lockPos, loc1.materials, EEquipRefreshNumType._EEquipRefreshNumBatch, loc1.expectAttr, 0, loc1.expectAttrAll, loc1.autoBuyTone, loc1.autoBuyLock);
            return;
        }

        protected /* override */ autoSelectedMaterial(): void
        {
            var loc1=_opertionType;
            switch (loc1) 
            {
                case EItemUpdateOper._EItemUpdateOperStrengthen:
                {
                    this.selectMaterialStrenthen();
                    break;
                }
                case EItemUpdateOper._EItemUpdateOperRecast:
                {
                    this.selectMaterialRecast();
                    break;
                }
                case EItemUpdateOper._EItemUpdateOperAdvance: case EItemUpdateOper._EItemUpdateOperAdvanceColor:
                {
                    this.selectMaterialEquipAdvance();
                    break;
                }
                case EItemUpdateOper._EItemUpdateDecompose:
                {
                    this.selectMaterialEquipDecompose();
                    break;
                }
                case EItemUpdateOper._EItemUpdateUpdradePrefix:
                {
                    this.selectMaterialUpgradeQuality();
                    break;
                }
                case EItemUpdateOper._EItemUpdateOperEquipSmelt:
                {
                    this.selectMaterialEquipMelt();
                    break;
                }
            }
            return;
        }

        /* internal  */selectMaterialStrenthen(): void
        {
            var loc2=0;
            var loc3=0;
            var loc4=null;
            var loc5=null;
            var loc8=null;
            if (_choosedEquipmentData.length == 0) 
            {
                return;
            }
            var loc1=[];
            var loc6=(_choosedEquipmentData[0] as ItemData).itemExInfo.strengthen;
            if (this._currentUpdateType == EItemUpdateType._EItemUpdateUpgrade && loc6 == 11) 
            {
                MsgManager.showRollTipsMsg(Language.getString(61024));
                return;
            }
            var loc7=cache.pack.backPackCache.getPropByType(EProp._EPropEquipStrengthenProp);
            var loc9=0;
            var loc10=loc7;
            for(loc4 of loc10) 
            {
                if (!(this._currentUpdateType == EItemUpdateType._EItemUpdateUpgrade && loc4.itemInfo.item.itemLevel == loc6 + 1 || this._currentUpdateType == EItemUpdateType._EItemUpdateRefresh && loc4.itemInfo.item.itemLevel == loc6)) 
                {
                    continue;
                }
                if (!_useBind && loc4.bind == EBind._EBindYes) 
                {
                    continue;
                }
                loc1.push({"item": loc4, "bind": loc4.itemInfo.item.bind, "level": loc4.itemInfo.item.itemLevel});
            }
            loc1.sortOn("level");
            loc1.sortOn("bind");
            if (_useBind) 
            {
                loc1.sortOn("bind", Array.DESCENDING);
            }
            loc5 = [];
            if (loc1.length > 0) 
            {
                loc5.push(loc1[0]["item"]);
            }
            if (loc5.length != 0) 
            {
                _view.update({"type":"autoChooseMaterial", "material": loc5, "isEnough": true});
            }
            else 
            {
                loc5 = [];
                loc8 = ItemConfig.instance.getPropsByType(EProp._EPropEquipStrengthenProp);
                loc2 = 0;
                while (loc2 < loc8.length) 
                {
                    loc4 = new ItemData((loc8[loc2] as ItemInfo).item.code);
                    if (this._currentUpdateType == EItemUpdateType._EItemUpdateUpgrade && loc4.itemInfo.item.itemLevel == loc6 + 1 && loc4.itemInfo.item.bind == EBind._EBindNo || this._currentUpdateType == EItemUpdateType._EItemUpdateRefresh && loc4.itemInfo.item.itemLevel == loc6 && loc4.itemInfo.item.bind == EBind._EBindNo) 
                    {
                        loc5.push(loc4);
                    }
                    ++loc2;
                }
                _view.update({"type":"autoChooseMaterial", "material": loc5, "isEnough": false});
            }
            this.selectPropStrengthen();
            return;
        }

        /* internal  */selectPropStrengthen(): void
        {
            var loc4=null;
            var loc5=0;
            var loc6=0;
            var loc7=null;
            if (choosedEquipmentData.length == 0) 
            {
                return;
            }
            if (_useLuckTuneNum == 0) 
            {
                _view.update({"type":"autoChooseLuckTune", "luckTune":[]});
                return;
            }
            var loc1=(_choosedEquipmentData[0] as ItemData).itemExInfo.strengthen;
            var loc2=cache.pack.backPackCache.getPropByType(EProp._EPropEquipStrengthenPerfectProp);
            var loc3=[];
            var loc8=0;
            var loc9=loc2;
            for(loc4 of loc9) 
            {
                if (!(this._currentUpdateType == EItemUpdateType._EItemUpdateRefresh && loc1 == loc4.itemInfo.item.itemLevel || this._currentUpdateType == EItemUpdateType._EItemUpdateUpgrade && loc1 + 1 == loc4.itemInfo.item.itemLevel)) 
                {
                    continue;
                }
                if (!_useBind && loc4.bind == EBind._EBindYes) 
                {
                    continue;
                }
                loc3.push({"item": loc4, "bind": loc4.itemInfo.item.bind, "level": loc4.itemInfo.item.itemLevel});
            }
            loc7 = [];
            if (loc3.length > 0) 
            {
                loc3.sortOn("level");
                loc3.sortOn("bind");
                if (_useBind) 
                {
                    loc3.sortOn("bind", Array.DESCENDING);
                }
                loc7.push(loc3[0]["item"]);
                _useLuckTuneNum = 1;
                _view.update({"type":"autoChooseLuckTune", "luckTune": loc7});
            }
            else 
            {
                if (_useLuckTuneNum == 1) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(61025));
                }
                _useLuckTuneNum = 0;
                _view.update({"type":"autoChooseLuckTune", "luckTune": loc7});
            }
            return;
        }

        /* internal  */selectMaterialRecast(): void
        {
            var loc1=null;
            var loc3=0;
            var loc4=null;
            var loc7=false;
            var loc8=null;
            var loc2=[];
            var loc5=[];
            if (choosedEquipmentData.length == 0) 
            {
                return;
            }
            loc1 = cache.pack.backPackCache.getPropItems();
            var loc6=[];
            loc3 = 0;
            while (loc3 < loc1.length) 
            {
                if ((loc4 = loc1[loc3] as ItemData).category == ECategory._ECategoryProp && loc4.itemInfo.item.type == EProp._EPropRefresh && loc4.itemInfo.item.color == (_choosedEquipmentData[0] as ItemData).itemInfo.item.color) 
                {
                    if (!(!_useBind && loc4.bind == EBind._EBindYes)) 
                    {
                        loc6.push({"data": loc4, "bind": loc4.itemInfo.item.bind});
                    }
                }
                ++loc3;
            }
            if (_useBind) 
            {
                loc6.sortOn("bind", Array.DESCENDING);
            }
            else 
            {
                loc6.sortOn("bind");
            }
            if (loc6.length > 0) 
            {
                loc7 = true;
                loc2.push({"data": loc6[0]["data"], "isEnough": loc7, "amount": 1});
            }
            else 
            {
                loc7 = false;
                loc8 = ItemConfig.instance.getPropsByType(EProp._EPropRefresh);
                loc3 = 0;
                while (loc3 < loc8.length) 
                {
                    if ((loc4 = new ItemData((loc8[loc3] as ItemInfo).item.code)).itemInfo.item.bind == EBind._EBindNo && loc4.itemInfo.item.color == (_choosedEquipmentData[0] as ItemData).itemInfo.item.color) 
                    {
                        break;
                    }
                    ++loc3;
                }
                loc2.push({"data": loc4, "isEnough": loc7, "amount": 1});
            }
            _view.update({"type":"autoChooseMaterial", "material": loc2});
            autoSelectedRecastLocks();
            return;
        }

        /* internal  */selectMaterialEquipAdvance(): void
        {
            var loc1=null;
            var loc3=null;
            var loc14=0;
            var loc15=null;
            var loc23=null;
            if (choosedEquipmentData.length == 0) 
            {
                return;
            }
            var loc2=_choosedEquipmentData[0] as ItemData;
            if (_opertionType != EItemUpdateOper._EItemUpdateOperAdvance) 
            {
                if (_opertionType == EItemUpdateOper._EItemUpdateOperAdvanceColor) 
                {
                    loc3 = EquipAdvanceConfig.instance.getAdvanceColorConfig(loc2);
                }
            }
            else 
            {
                loc3 = EquipAdvanceConfig.instance.getAdvanceConfig(loc2);
            }
            if (!loc3) 
            {
                return;
            }
            var loc4=loc3.specialMaterialItemCode == 0 ? null : new ItemData(loc3.specialMaterialItemCode);
            var loc5=loc3.normalMaterialItemCode == 0 ? null : new ItemData(loc3.normalMaterialItemCode);
            var loc6=loc3.extendMaterialItemCode == 0 ? null : new ItemData(loc3.extendMaterialItemCode);
            var loc7=loc3.extendMaterialItemCode1 == 0 ? null : new ItemData(loc3.extendMaterialItemCode1);
            var loc8=loc3.extendMaterialItemCode2 == 0 ? null : new ItemData(loc3.extendMaterialItemCode2);
            var loc9=loc3.extendMaterialItemCode3 == 0 ? null : new ItemData(loc3.extendMaterialItemCode3);
            var loc10=loc3.protectPropItemCode == 0 ? null : new ItemData(loc3.protectPropItemCode);
            var loc11=[];
            var loc12=[];
            var loc13=Cache.instance.pack.backPackCache.getPropItems();
            var loc16=[];
            var loc17=[];
            var loc18=[];
            var loc19=[];
            var loc20=[];
            var loc21=[];
            var loc22=[];
            loc14 = 0;
            while (loc14 < loc13.length) 
            {
                if ((loc15 = loc13[loc14] as ItemData).category == ECategory._ECategoryProp) 
                {
                    if (!(!_useBind && loc15.bind == EBind._EBindYes)) 
                    {
                        loc1 = {"bind": loc15.itemInfo.item.bind, "data": loc15};
                        if (loc4 && (loc15.itemCode == loc4.itemCode || loc15.itemCode == loc4.itemInfo.item.codeUnbind)) 
                        {
                            loc16.push(loc1);
                        }
                        else if (loc5 && (loc15.itemCode == loc5.itemCode || loc15.itemCode == loc5.itemInfo.item.codeUnbind)) 
                        {
                            loc17.push(loc1);
                        }
                        else if (loc6 && (loc15.itemCode == loc6.itemCode || loc15.itemCode == loc6.itemInfo.item.codeUnbind)) 
                        {
                            loc18.push(loc1);
                        }
                        else if (loc7 && (loc15.itemCode == loc7.itemCode || loc15.itemCode == loc7.itemInfo.item.codeUnbind)) 
                        {
                            loc19.push(loc1);
                        }
                        else if (loc8 && (loc15.itemCode == loc8.itemCode || loc15.itemCode == loc8.itemInfo.item.codeUnbind)) 
                        {
                            loc20.push(loc1);
                        }
                        else if (loc9 && (loc15.itemCode == loc9.itemCode || loc15.itemCode == loc9.itemInfo.item.codeUnbind)) 
                        {
                            loc21.push(loc1);
                        }
                        else if (loc10 && (loc15.itemCode == loc10.itemCode || loc15.itemCode == loc10.itemInfo.item.codeUnbind)) 
                        {
                            loc22.push(loc1);
                        }
                    }
                }
                ++loc14;
            }
            if (_useBind) 
            {
                loc16.sortOn("bind", Array.DESCENDING);
                loc17.sortOn("bind", Array.DESCENDING);
                loc18.sortOn("bind", Array.DESCENDING);
                loc19.sortOn("bind", Array.DESCENDING);
                loc20.sortOn("bind", Array.DESCENDING);
                loc21.sortOn("bind", Array.DESCENDING);
                loc22.sortOn("bind", Array.DESCENDING);
            }
            else 
            {
                loc16.sortOn("bind");
                loc17.sortOn("bind");
                loc18.sortOn("bind");
                loc19.sortOn("bind");
                loc20.sortOn("bind");
                loc21.sortOn("bind");
                loc22.sortOn("bind");
            }
            if (loc4) 
            {
                loc11.push(this.getMaterialObject(loc4, loc3.specialMaterialNum, loc16, loc12));
            }
            if (loc5) 
            {
                loc11.push(this.getMaterialObject(loc5, loc3.normalMaterialNum, loc17, loc12));
            }
            if (loc6) 
            {
                loc11.push(this.getMaterialObject(loc6, loc3.extendMaterialNum, loc18, loc12));
            }
            if (loc7) 
            {
                loc11.push(this.getMaterialObject(loc7, loc3.extendMaterialNum1, loc19, loc12));
            }
            if (loc8) 
            {
                loc11.push(this.getMaterialObject(loc8, loc3.extendMaterialNum2, loc20, loc12));
            }
            if (loc9) 
            {
                loc11.push(this.getMaterialObject(loc9, loc3.extendMaterialNum3, loc21, loc12));
            }
            _view.update({"type":"autoChooseMaterial", "material": loc11, "useItems": loc12});
            if (_opertionType == EItemUpdateOper._EItemUpdateOperAdvanceColor) 
            {
                return;
            }
            if (loc3.lossRateStrengthen == 0 && loc3.lossRatePrefix == 0) 
            {
                _view.update({"type":"autoChooseLuckTune", "luckTune":[], "protectedPropNeeded": false});
                return;
            }
            if (loc10) 
            {
                if (_useLuckTuneNum > 0 && loc22.length > 0) 
                {
                    loc23 = loc22[0]["data"];
                    _useLuckTuneNum = 1;
                    _view.update({"type":"autoChooseLuckTune", "luckTune":[loc23], "protectedPropNeeded": true});
                }
                else 
                {
                    if (_useLuckTuneNum > 0) 
                    {
                        MsgManager.showRollTipsMsg(loc10.name + Language.getString(61026));
                    }
                    _useLuckTuneNum = 0;
                    _view.update({"type":"autoChooseLuckTune", "luckTune":[], "protectedPropNeeded": true});
                }
            }
            else 
            {
                if (_useLuckTuneNum > 0) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(61027));
                }
                _useLuckTuneNum = 0;
                _view.update({"type":"autoChooseLuckTune", "luckTune":[], "protectedPropNeeded": true});
            }
            return;
        }

        /* internal  */getMaterialObject(arg1: ItemData, arg2: int, arg3: Array<any>, arg4: Array<any>=null): Object
        {
            var loc1=0;
            var loc4=0;
            var loc2=false;
            var loc3;
            (loc3 = new ItemData(arg1.itemInfo.item.codeUnbind)).itemAmount = arg2;
            if (arg3.length > 0) 
            {
                loc1 = 0;
                loc4 = 0;
                while (loc4 < arg3.length) 
                {
                    loc1 = loc1 + (arg3[loc4].data as ItemData).itemAmount;
                    if (arg4) 
                    {
                        arg4.push(arg3[loc4].data);
                    }
                    if (loc1 >= arg2) 
                    {
                        loc2 = true;
                    }
                    ++loc4;
                }
            }
            if (loc2) 
            {
                (loc3 = new ItemData(arg3[0]["data"].itemCode)).itemAmount = arg2;
            }
            return {"enough": loc2, "data": loc3};
        }

        /* internal  */selectMaterialEquipDecompose(): void
        {
            var loc1=0;
            var loc2=0;
            var loc3=null;
            var loc6=null;
            var loc7=null;
            var loc8=null;
            var loc4=new Map<any, any> /* flash.utils.Dictionary */();
            var loc5=[];
            loc2 = 0;
            while (loc2 < _choosedEquipmentData.length) 
            {
                loc3 = _choosedEquipmentData[loc2] as ItemData;
                if (loc3) 
                {
                    loc5 = loc5.concat(this.getDecomposeGain(loc3));
                }
                ++loc2;
            }
            var loc9=0;
            var loc10=loc5;
            for(loc6 of loc10) 
            {
                if (loc4[loc6.itemData.name] == null) 
                {
                    loc4[loc6.itemData.name] = loc6;
                    continue;
                }
                (loc4[loc6.itemData.name] as TempRefreshData).itemInfo = loc6.itemData.itemInfo;
                (loc4[loc6.itemData.name] as TempRefreshData).amount = (loc4[loc6.itemData.name] as TempRefreshData).amount + loc6.amount;
            }
            loc8 = [];
            loc9 = 0;
            loc10 = loc4;
            for(loc6 of loc10) 
            {
                (loc7 = loc6.itemData).itemAmount = loc6.amount;
                loc8.push(loc7);
            }
            loc8.sortOn("code", Array.NUMERIC);
            _view.update({"type":"autoChooseMaterial", "material": loc8, "isEnough": true});
            return;
        }

        /* internal  */getDecomposeGain(arg1: ItemData): Array<any>
        {
            var loc2=null;
            var loc3=null;
            var loc6=0;
            var loc7=null;
            var loc8=null;
            var loc9=null;
            var loc10=null;
            var loc1=ItemConfig.instance.getPropsByType(EProp._EPropRefresh);
            var loc4=loc1.length;
            var loc5=0;
            if (ItemsUtil.isHeartLock(arg1)) 
            {
                loc7 = [];
                loc8 = EquipAdvanceConfig.instance.equipAdvanceConfigMap_level;
                loc3 = null;
                var loc11=0;
                var loc12=loc8;
                for(loc9 of loc12) 
                {
                    if (!(loc9.equipType == arg1.type && loc9.oldLevelSection < arg1.itemInfo.item.level)) 
                    {
                        continue;
                    }
                    if (loc3 == null) 
                    {
                        (loc3 = new TempRefreshData(loc9.normalMaterialItemCode)).amount = loc9.normalMaterialNum;
                        continue;
                    }
                    loc3.amount = loc3.amount + loc9.normalMaterialNum;
                }
                if (loc3) 
                {
                    loc7.push(loc3);
                }
                loc3 = null;
                loc5 = 0;
                while (loc5 < arg1.itemExInfo.prefix) 
                {
                    loc10 = EquipAdvanceConfig.instance.getPrefixUpgradeInfoByParams(arg1.type, loc5);
                    if (loc3 != null) 
                    {
                        loc3.amount = loc3.amount + loc10.materialHolySpecialAmount;
                    }
                    else 
                    {
                        (loc3 = new TempRefreshData(loc10.materialHolySpecialItemCode)).amount = loc10.materialHolySpecialAmount;
                    }
                    ++loc5;
                }
                if (loc3) 
                {
                    loc7.push(loc3);
                }
                return loc7;
            }
            loc5 = 0;
            while (loc5 < loc4) 
            {
                loc2 = loc1[loc5] as ItemInfo;
                if (arg1.itemInfo.item.level < 40) 
                {
                    loc6 = EBind._EBindYes;
                }
                else 
                {
                    loc6 = arg1.itemExInfo.bind != EBind._EBindYes ? EBind._EBindNo : _EBindYes;
                }
                if (loc2.item.color == arg1.itemInfo.item.color && loc2.item.bind == loc6) 
                {
                    (loc3 = new TempRefreshData(loc2.item.code)).amount = 1;
                    return [loc3];
                }
                ++loc5;
            }
            return [];
        }

        /* internal  */selectMaterialUpgradeQuality(): void
        {
            var loc1=0;
            var loc2=null;
            var loc8=null;
            var loc14=0;
            var loc15=0;
            var loc16=null;
            var loc3=[];
            if (choosedEquipmentData.length == 0) 
            {
                return;
            }
            var loc4=_choosedEquipmentData[0] as ItemData;
            var loc5;
            if (!(loc5 = EquipAdvanceConfig.instance.getPrefixUpgradeInfo(loc4.type, loc4.itemInfo.item.level, loc4.itemExInfo.prefix))) 
            {
                return;
            }
            var loc6=loc5.amount > 0;
            var loc7=false;
            if (loc5.materialHolySpecialItemCode > 0 && loc5.materialHolySpecialAmount > 0) 
            {
                loc7 = true;
                loc8 = new ItemData(loc5.materialHolySpecialItemCode);
            }
            var loc9=cache.pack.backPackCache.getPropItems();
            if (_useBind) 
            {
                loc9.sortOn("bind", Array.DESCENDING);
            }
            else 
            {
                loc9.sortOn("bind");
            }
            var loc10=false;
            var loc11=loc7 ? false : true;
            var loc12=[];
            var loc13=[];
            loc1 = 0;
            while (loc1 < loc9.length) 
            {
                loc2 = loc9[loc1] as ItemData;
                if (!(!_useBind && loc2.bind == EBind._EBindYes)) 
                {
                    if (loc2.type == EProp._EPropUpgradePrefix && loc2.itemInfo.item.effect == loc5.materialEffect) 
                    {
                        if (!loc10 && loc6) 
                        {
                            loc12.push(loc2);
                            if ((loc14 = loc14 + loc2.itemAmount) >= loc5.amount) 
                            {
                                loc10 = true;
                            }
                        }
                    }
                    else if (loc8 && (loc2.itemCode == loc8.itemCode || loc2.itemCode == loc8.itemInfo.item.codeUnbind)) 
                    {
                        if (!loc11 && loc7) 
                        {
                            loc13.push(loc2);
                            if ((loc15 = loc15 + loc2.itemAmount) >= loc5.materialHolySpecialAmount) 
                            {
                                loc11 = true;
                            }
                        }
                    }
                }
                ++loc1;
            }
            if (loc6) 
            {
                if (loc10) 
                {
                    loc3.push({"material": loc12, "isEnough": loc10, "amountNeed": loc5.amount});
                }
                else 
                {
                    loc16 = ItemConfig.instance.getPropsByType(EProp._EPropUpgradePrefix);
                    loc1 = 0;
                    while (loc1 < loc16.length) 
                    {
                        loc2 = new ItemData((loc16[loc1] as ItemInfo).item.code);
                        if (loc2.itemInfo.item.bind == EBind._EBindNo && loc2.itemInfo.item.effect == loc5.materialEffect) 
                        {
                            loc3.push({"material":[loc2], "isEnough": loc10, "amountNeed": loc5.amount});
                        }
                        ++loc1;
                    }
                }
            }
            if (loc7) 
            {
                if (loc11) 
                {
                    loc3.push({"material": loc13, "isEnough": loc11, "amountNeed": loc5.materialHolySpecialAmount});
                }
                else 
                {
                    loc3.push({"material":[new ItemData(loc8.itemInfo.item.codeUnbind)], "isEnough": loc11, "amountNeed": loc5.materialHolySpecialAmount});
                }
            }
            _view.update({"type":"autoChooseMaterial", "material": loc3});
            return;
        }

        /* internal  */selectMaterialEquipMelt(): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=null;
            var loc11=null;
            if (choosedEquipmentData.length < 2) 
            {
                _view.update({"type":"autoChooseMaterial", "useItems":[], "amountNeed": 0, "isEnough": false});
                return;
            }
            var loc4=[];
            var loc5=_choosedEquipmentData[0] as ItemData;
            var loc6=_choosedEquipmentData[1] as ItemData;
            var loc7;
            if (!(loc7 = EquipAdvanceConfig.instance.getEquipMeltInfo((loc5.itemInfo.extend as TItemWeapon).suit, (loc6.itemInfo.extend as TItemWeapon).suit))) 
            {
                return;
            }
            loc1 = Cache.instance.pack.backPackCache.getPropByType(EProp._EPropMelt);
            var loc8=[];
            loc2 = 0;
            while (loc2 < loc1.length) 
            {
                loc3 = loc1[loc2] as ItemData;
                if (!(!_useBind && loc3.bind == EBind._EBindYes)) 
                {
                    loc8.push({"data": loc3, "bind": loc3.itemInfo.item.bind});
                }
                ++loc2;
            }
            if (_useBind) 
            {
                loc8.sortOn("bind", Array.DESCENDING);
            }
            else 
            {
                loc8.sortOn("bind");
            }
            var loc9=false;
            var loc10=0;
            loc2 = 0;
            while (loc2 < loc8.length) 
            {
                loc3 = loc8[loc2]["data"] as ItemData;
                loc4.push(loc3);
                if ((loc10 = loc10 + loc3.itemAmount) >= loc7.propNum) 
                {
                    loc9 = true;
                    break;
                }
                ++loc2;
            }
            if (loc9) 
            {
                _view.update({"type":"autoChooseMaterial", "useItems": loc4, "amountNeed": loc7.propNum, "isEnough": true});
            }
            else 
            {
                if (loc4.length == 0) 
                {
                    loc11 = ItemConfig.instance.getPropsByType(EProp._EPropMelt);
                    loc2 = 0;
                    while (loc2 < loc11.length) 
                    {
                        loc3 = new ItemData((loc11[loc2] as ItemInfo).item.code);
                        if (loc3.itemInfo.item.bind == EBind._EBindNo) 
                        {
                            loc4.push(loc3);
                        }
                        ++loc2;
                    }
                }
                _view.update({"type":"autoChooseMaterial", "useItems": loc4, "amountNeed": loc7.propNum, "isEnough": false});
            }
            return;
        }

        /* internal  */onGuideEquipBuildHandler(arg1: DataEvent): void
        {
            if (_view && !_view.isHide) 
            {
                (_view as IEquipmentModule).checkGuide();
            }
            return;
        }

        protected /* override */ doCastHandler(arg1: DataEvent): void
        {
            if (view.isHide) 
            {
                view.show();
            }
            var loc1=arg1.type;
            switch (loc1) 
            {
                case EventName.Equipment_DoCast_Strengthen:
                {
                    showToPanel(EItemUpdateOper._EItemUpdateOperStrengthen);
                    if (arg1.data) 
                    {
                        _view.update({"type":"doCast", "data": arg1.data as ItemData});
                    }
                    break;
                }
                case EventName.Equipment_DoCast_Recast:
                {
                    showToPanel(EItemUpdateOper._EItemUpdateOperRecast);
                    if (arg1.data) 
                    {
                        _view.update({"type":"doCast", "data": arg1.data as ItemData});
                    }
                    break;
                }
                case EventName.Equipment_DoCast_EquipDecompose:
                {
                    showToPanel(EItemUpdateOper._EItemUpdateDecompose);
                    break;
                }
                case EventName.Equipment_DoCast_EquipMerge:
                {
                    showToPanel(EItemUpdateOper._EItemUpdateOperMerge);
                    break;
                }
                case EventName.Equipment_DoCast_EquipAdvance:
                {
                    showToPanel(EItemUpdateOper._EItemUpdateOperAdvance);
                    break;
                }
                case EventName.Equipment_DoCast_EquipAdvanceColor:
                {
                    showToPanel(EItemUpdateOper._EItemUpdateOperAdvanceColor);
                    break;
                }
                case EventName.Equipment_DoCast_EquipPrefixUpgrade:
                {
                    showToPanel(EItemUpdateOper._EItemUpdateUpdradePrefix);
                    break;
                }
            }
            return;
        }

        private /* var */_equipModule: IEquipmentModule;

        private /* var */_currentUpdateType: int=0;
    }
